//package com.zmn.plat.task.job.channel;
//
//import com.github.ltsopensource.core.domain.Action;
//import com.github.ltsopensource.core.domain.Job;
//import com.github.ltsopensource.spring.tasktracker.JobRunnerItem;
//import com.github.ltsopensource.spring.tasktracker.LTS;
//import com.github.ltsopensource.tasktracker.Result;
//import com.zmn.common.constant.GlobalConsts;
//import com.zmn.common.dto.ResultDTO;
//import com.zmn.common.utils.date.DateUtil;
//import com.zmn.manager.lts.interfaces.task.TaskManager;
//import com.zmn.plat.business.interfaces.channel.ChannelBService;
//import com.zmn.plat.common.constant.ChannelConsts;
//import com.zmn.plat.manager.dictionary.ChannelDict;
//import com.zmn.plat.model.entity.channel.Channel;
//import com.zmn.plat.model.entity.channel.ChannelQuery;
//import com.zmn.plat.services.interfaces.channel.ChannelService;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//
//import javax.annotation.PostConstruct;
//import java.util.Date;
//import java.util.List;
//
//
///**
// * 渠道接入方式更新JOB：如果接入方式选择为临时接入，则30天后将该渠道禁用
// *
// * @author linfeng
// * @since 2019/10/31 15:28:09
// */
//@LTS
//public class ChannelAccessModeJob {
//
//    private Logger logger = LoggerFactory.getLogger(ChannelAccessModeJob.class);
//
//    @Autowired
//    private ChannelService channelService;
//
//    @Autowired
//    private ChannelBService channelBService;
//
//    @Autowired
//    private TaskManager taskManager;
//
//    /**
//     * Init.
//     */
//    @PostConstruct
//    void init() {
//        Job job = new Job();
//        job.setTaskId(ChannelConsts.TASK_ID_CHANNEL_ACCESS_MODE);
//        job.setParam(TaskManager.SHARD_FIELD, ChannelConsts.TASK_ID_CHANNEL_ACCESS_MODE);
//        // 每日1点执行
//        job.setCronExpression("0 0 1 * * ?");
//        job.setReplaceOnExist(true);
//        ResultDTO result = taskManager.submitTask(job);
//        if (!result.getStatusBool()) {
//            logger.error("#channel_access_mode# job submit fail...");
//        }
//    }
//
//    /**
//     * 渠道接入方式如果为临时接入，则30天后自动设置为禁用
//     *
//     * @param job the job
//     * @return result
//     */
//    @JobRunnerItem(shardValue = ChannelConsts.TASK_ID_CHANNEL_ACCESS_MODE)
//    public Result runChannelAccessModeJob(Job job) {
//
//        logger.debug("#job#channel_access_mode#start running...");
//
//        ChannelQuery channelQuery = new ChannelQuery();
//        channelQuery.setStatus(GlobalConsts.YES);
//        // 一级渠道已废弃接入方式字段, 不做处理
//        channelQuery.setRank(ChannelDict.RANK_TWO);
//        channelQuery.setAccessMode(ChannelConsts.CHANNEL_ACCESS_MODE_TEMPORARY);
//        List<Channel> channels = channelService.listByQuery(channelQuery);
//        Integer count = 0;
//        if (channels != null && channels.size() > 0) {
//            for (Channel channel : channels) {
//                Date lastDate = channel.getUpdateTime() == null ? channel.getCreateTime() : channel.getUpdateTime();
//                lastDate = DateUtil.addDays(lastDate, 30);
//                long overdueTime = lastDate.getTime();
//                if (overdueTime <= System.currentTimeMillis()) {
//                    channel.setStatus(GlobalConsts.NO);
//                    channel.setUpdateTime(DateUtil.getNow());
//                    channel.setUpdater("SYSTEM");
//                    channelBService.updateStatusByKey(channel);
//                    count++;
//                }
//            }
//        }
//
//        logger.debug("#job#channel_access_mode#end running... update count :" + count);
//        return new Result(Action.EXECUTE_SUCCESS, "渠道接入方式任务更新完成! update count:" + count);
//    }
//}
